package com.lw.smartdevice.tasks;

import com.lw.smartdevice.events.DeviceStatusCheckEvent;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

/**
 * @author Administrator
 * @version 1.0
 * @description:
 * @date 2022/3/27 15:56
 */
@EnableScheduling
@Component
public class DeviceStatusCheckTask {

    private ApplicationContext context;

    @Autowired
    public void setContext(ApplicationContext context) {
        this.context = context;
    }

    @Scheduled(fixedRate = 45000)
    public void checkStatus(){
        //检查设备最后以西时间，遍历所有设备
        context.publishEvent(new DeviceStatusCheckEvent());
    }
}
